<%@ page import="java.sql.*" %>
<%@ page import="user.User" %>
<%@ page import="com.example.demo_text.databaseaccess" %>
<%@ page import="com.example.demo_text.Course" %>
<%@ page import="java.util.List" %>
<%@ page import="com.example.demo_text.CourseDAO" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>我的课程</title>
    <style>
        /* 全局样式 */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Segoe UI', 'PingFang SC', 'Microsoft Yahei', sans-serif;
            background: linear-gradient(135deg, #e0f7fa, #f3e5f5);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 40px 20px;
            color: #333;
        }

        .card {
            background: white;
            width: 100%;
            max-width: 300px;
            padding: 30px 25px;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
        }

        h1 {
            text-align: center;
            margin-bottom: 24px;
            font-weight: 600;
            color: #374151;
        }

        .course-list {
            display: flex;
            flex-direction: column;
            gap: 1rem;
            margin-top: 1rem;
        }

        .course-item {
            padding: 15px;
            background: #f3f4f6;
            border-radius: 6px;
            text-align: center;
            transition: all 0.3s;
            cursor: pointer;
        }

        .course-item:hover {
            background: #e5e7eb;
            transform: translateY(-2px);
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        a {
            color: #15576b;
            text-decoration: none;
            display: block;
        }

        .btn-add-course {
            display: inline-block;
            margin-top: 20px;
            padding: 12px 20px;
            background-color: #10b981;
            color: white;
            text-align: center;
            font-weight: 600;
            border-radius: 8px;
            text-decoration: none;
            transition: background-color 0.3s ease;
            text-align: center;
        }

        .btn-add-course:hover {
            background-color: #059669;
        }
    </style>
</head>
<body>

<div class="card">
    <h1>我的课程</h1>


    <%
        User CurUser = (User) session.getAttribute("user");
        if (CurUser != null) {
    %>
    <p>当前用户ID：<%= CurUser.getId() %></p>
    <%
    } else {
    %>
    <p style="color:red;">用户未登录</p>
    <%
        }
    %>



    <div class="course-list">
        <%
            CurUser = (User) session.getAttribute("user");
            if (CurUser != null) {
                int userId = CurUser.getId();
                List<Course> courses = CourseDAO.getCoursesByUserId(userId);

                if (!courses.isEmpty()) {
                    for (Course course : courses) {
        %>
        <a href="class_space.jsp?course_id=<%= course.getId() %>" class="course-item">
            <%= course.getName() %>
        </a>
        <%
            }
        } else {
        %>
        <p style="color:gray;">暂无课程</p>
        <%
            }
        } else {
        %>
        <p style="color:red;">用户未登录</p>
        <%
            }
        %>
    </div>

    <!-- 添加课程按钮 -->
    <a href="add_course.jsp" class="btn-add-course">+ 添加课程</a>
    <a href="home.jsp" class="btn-add-course">返回主页</a>
</div>

</body>
</html>
